"use strict";
const render_command_1 = require("@x.render/render-command");
const child_process_1 = require("child_process");
const render_node_utils_1 = require("@x.render/render-node-utils");
class StartCommand extends render_command_1.RenderCommand {
    constructor(rest, options, cmd) {
        super(rest, options, cmd);
        this.exec();
    }
    init() {
        // TODO
    }
    exec() {
        const nProcessArgv = process.argv.slice(2);
        const result = (0, child_process_1.spawnSync)("npx", ["render-builder", "start", ...nProcessArgv], {
            stdio: ["inherit", "inherit", "inherit"],
        });
        if (result.signal) {
            if (result.signal) {
                if (result.signal === "SIGKILL") {
                    render_node_utils_1.log.warn("The build failed because the process exited too early. " +
                        "This probably means the system ran out of memory or someone called " +
                        "`kill -9` on the process.");
                }
                else if (result.signal === "SIGTERM") {
                    render_node_utils_1.log.warn("The build failed because the process exited too early. " +
                        "Someone might have called `kill` or `killall`, or the system could " +
                        "be shutting down.");
                }
                process.exit(1);
            }
        }
        process.exit(result.status);
    }
}
module.exports = (rest, options, cmd) => {
    return new StartCommand(rest, options, cmd);
};
